
from http.server import HTTPServer, BaseHTTPRequestHandler
import app
import json
 
data = {'result': 'this is a test'}
host = ('localhost', 8888)
 
class Resquest(BaseHTTPRequestHandler):
    def do_GET(self):
        self.send_response(200)
        self.send_header('Content-type', 'application/json')
        self.end_headers()
        path = str(self.path) 
        
        sdata=app.doWork(path); 
        print(path)
        self.wfile.write(json.dumps(sdata).encode())
    def do_POST(self):
        self.send_response(200)
        self.send_header('Content-type', 'application/json')
        self.end_headers()
        params=self.rfile.readline(int(self.headers['content-length']));        
        sdata=app.doWork(json.loads(params));        
        self.wfile.write(json.dumps(sdata).encode())
 
if __name__ == '__main__':
    server = HTTPServer(host, Resquest)
    print("DelphiWebMVC-Python服务: %s:%s" % host)
    server.serve_forever()